<!--
 * @Author: zhangjingyu
 * @Date: 2021-04-01 16:50:58
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2021-04-08 13:47:36
 * @FilePath: \vprisk10.14\src\views\ftpManage\pricingManage\sceneTask\filterFormItem.vue
 * @Description: 数据筛选项动态表单控件
-->
<template>
  <div style="margin-bottom:5px">
    <el-checkbox
      v-model="itemObj.checked"
      style="display:inline-block;width:30%;margin-right:5%;overflow: hidden;"
      :title="itemObj.elementName"
      >{{ itemObj.elementName }}</el-checkbox
    >
    <el-select
      v-model="itemObj.op"
      style="display:inline-block;width:20%;margin-right:5%"
      @change="clearv"
      v-show="itemObj.checked"
    >
      <el-option
        v-for="item in getOpList"
        :key="item.value"
        :value="item.value"
        :label="item.label"
      ></el-option>
    </el-select>
    <div name="动态输入框列表" 
      v-show="itemObj.checked"
    style="display:inline-block;width:35%;margin-right:5%">
      <auto-form
        :multiple="true"
        :elementType="realType"
        :elementField="itemObj.elementField"
        :dimCode="itemObj.dimensionCode"
        :daterange="itemObj.op === '><'"
        v-model="itemObj.v"
        v-if="!(itemObj.op === '><'&&realType==='2')"
      >
      </auto-form>
      <!-- 数字类型介于 -->
      <template v-if="itemObj.op === '><'&&realType==='2'">
      <el-input v-model="itemObj.v" style="display:inline-block;width:45%;margin-right:10%"></el-input>
      <el-input v-model="itemObj.vn" style="display:inline-block;width:45%;"></el-input>
      </template>
      <!-- 期限类型 -->
      <template v-if="realType==='5'">
      <el-input v-model="itemObj.v" style="display:inline-block;width:25%;margin-right:5%"></el-input>
      <el-select v-model="itemObj.vMult" style="display:inline-block;width:70%;">
        <el-option v-for="item in termList" :key="item.value"
        :value="item.value"
        :label="item.label"></el-option>
      </el-select>
      </template>
    </div>
  </div>
</template>

<script>
import autoForm from "@/components/ftp/autoForm.vue";

export default {
  components: { autoForm },
  data() {
    return {
      // 元素类型1字符，2数值，3日期，4字典和口径(包含维度)，5期限
      dataType: {
        "1": "text",
        "2": "number",
        "3": "date",
        "4": "dict",
        "5": "term",
        "6": "dict",
        "7": "dict",
      },
      text: [
        { value: "=", label: "等于" },
        { value: "!=", label: "不等于" },
        { value: "~", label: "模糊" }
      ],
      date: [
        { value: "=", label: "等于" },
        { value: "!=", label: "不等于" },
        { value: ">", label: "大于" },
        { value: ">=", label: ">=" },
        { value: "<=", label: "<=" },
        { value: "<", label: "小于" },
        { value: "><", label: "介于" }
      ],
      number: [
        { value: "=", label: "等于" },
        { value: ">", label: "大于" },
        { value: ">=", label: ">=" },
        { value: "<=", label: "<=" },
        { value: "<", label: "小于" },
        { value: "><", label: "介于" }
      ],
      dict: [
        { value: "=", label: "等于" },
        { value: "C", label: "业务口径" }
      ],
      term: [{ value: "=", label: "等于" }],
      // 期限单位下拉框
      termList: [{value:'Y',label:'年'},{value:'M',label:'月'},{value:'D',label:'日'},],
      // 维度类型
      dims: {
        cpm_dim_organ: true,
        cpm_dim_subject: true,
        cpm_dim_product: true,
        cpm_dim_industry: true,
        CPM_DIM_ORGAN: true,
        CPM_DIM_SUBJECT: true,
        CPM_DIM_PRODUCT: true,
        CPM_DIM_INDUSTRY: true
      }
    };
  },
  computed: {
    getOpList() {let list = []
    if(this.itemObj.dimensionCode==='cpm_dim_currency'||this.itemObj.dimensionCode==='CPM_DIM_CURRENCY'){
        list = this.dict
    }else{
        list = this[this.dataType[this.itemObj.elementType] || "text"]
    }
      return list;
    },
    realType() {
      let type = this.itemObj.elementType;
      if (this.itemObj.elementType === "4") {
        // 维度情况，dimcode是特定维度
        if (this.dims[this.itemObj.dimensionCode]&&this.itemObj.op === "=") {
          type = "6";
        }
      }
        // 币种情况
        if (
          this.itemObj.dimensionCode === "CPM_DIM_CURRENCY" ||
          this.itemObj.dimensionCode === "cpm_dim_currency"
        ) {
          type = "8";
        }
          // 业务口径
        if (this.itemObj.op === "C") {
          type = "C";
        }
      return type;
    }
  },
  props: {
    itemObj: Object
  },
  methods: {
    clearv() {
      let type = this.realType;
      if (type === "1") {
        this.itemObj.v = "";
      }
      if (type === "2" && this.itemObj.op != "><") {
        this.itemObj.v = "";
      }
      if (type === "2" && this.itemObj.op === "><") {
        (this.itemObj.v = ""), (this.itemObj.vn = "");
      }
      if (type === "3" && this.itemObj.op != "><") {
        this.itemObj.v = "";
      }
      if (type === "3" && this.itemObj.op === "><") {
        this.itemObj.v = [];
      }
      if (type === "4") {
        this.itemObj.v = [];
      }
      if (type === "5") {
        (this.itemObj.v = ""), (this.itemObj.vMult = "");
      }
      if (type === "6") {
        this.itemObj.v = [];
      }
      if (type === "C") {
        this.itemObj.v = [];
      }
      this.$forceUpdate();
               console.log("现在的类型：",type)

    }
  }
};
</script>

<style lang="scss" scoped>
</style>